<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class UserResetSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->truncateTable();
        $this->call([
            UserSeeder::class
        ]);
    }

    private function truncateTable()
    {
        $tableNames = config('permission.table_names');
        Schema::disableForeignKeyConstraints();
        DB::table($tableNames['model_has_permissions'])->truncate();
        DB::table($tableNames['model_has_roles'])->truncate();
        DB::table($tableNames['role_has_permissions'])->truncate();
        DB::table($tableNames['roles'])->truncate();
        DB::table($tableNames['permissions'])->truncate();
        DB::table('users')->truncate();
        DB::table('system_menus')->truncate();
        Schema::enableForeignKeyConstraints();
    }
}
